home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / PAPTool / Preprocess.c < prev    next >
Encoding:
Text File  |  1992-11-29  |  1.6 KB  |  83 lines  |  [TEXT/MPS ]

  1. //    ©1992 Conrad Carlen & Manuel Veloso. All rights reserved.
  2. #ifndef _PREPROCESS_
  3. #include "Preprocess.h"
  4. #endif
  5.  
  6. #ifndef __STRING__
  7. #include <string.h>
  8. #endif
  9.  
  10. #ifdef _cplusplus
  11. extern "C"
  12. {
  13. #endif
  14. short stripLF(char *buffer, const short count);
  15. short stripEcho(char *buffer, short count, char *compare);
  16. short addReturn(char *buffer, short count);
  17. short stripExecutivePrompt(char *buffer, short count);
  18. #ifdef _cplusplus
  19. }
  20. #endif
  21.  
  22. short preprocessRead(char *buffer, short count, char */* compare */)
  23. {
  24.     count = stripLF(buffer, count);
  25. //    count = stripEcho(buffer, count, compare);            // should be after lf conversion, since it checks returns
  26.     return count;
  27. }
  28.  
  29. short stripLF(char *buffer, const short count)
  30. {
  31.     char    *scan = buffer;
  32.     char    *stop = scan + count;
  33.     
  34.     do
  35.     {
  36.         if (*scan == 0x0a)
  37.         {
  38.             *scan = 0x0d;
  39.         }
  40.         scan++;
  41.     } while (scan < stop);
  42.     return count;
  43. }
  44.  
  45. short stripEcho(char *buffer, short count, char *compare)
  46. {
  47.     if (!memcmp(buffer, compare, count))
  48.     {
  49.         count = 0;                            // it’s an echo! Kill it off.
  50.     }
  51.     return count;
  52. }
  53.  
  54. short preprocessWrite(char *buffer, short count)
  55. {
  56.     count = stripExecutivePrompt(buffer, count);
  57.     count = addReturn(buffer, count);                // replaces trailing null w/return, so no clib stuff after this
  58.     return count;
  59. }
  60.  
  61. short addReturn(char *buffer, short count)
  62. {
  63.     buffer[count-1] = 0x0d;
  64.     return count;
  65. }
  66.  
  67. short stripExecutivePrompt(char *buffer, short count)
  68. {
  69.     char    *theString = buffer, *theSubstring;
  70.     short    length;
  71.     
  72.     if ((theString[0] == 'P') && (theString[1] == 'S'))
  73.     {
  74.         length = 2;
  75.         while (theString[length] == '>')
  76.         {
  77.             length++;
  78.         }
  79.         memcpy(theString, theString+length, strlen(theString));
  80.         count -= length;
  81.     }
  82.     return count;
  83. }